package com.mypackage.LocationPattern;

import java.security.InvalidParameterException;
import java.util.Scanner;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class TestCaseHandler extends Activity{
	
	private static final String TAG = "@TestCaseHandler";
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
	}
	
	protected int countLines(){
		try{
			Scanner input = new Scanner(getResources().openRawResource(R.raw.test_case));
			int count = 0;
			
			while (input.hasNext()){
				count++;
				input.nextLine();
			}
			return count;
		}
		catch (Exception e){
			Log.v(TAG, "test_case: File Not Found");
			return 0;
		}
	}
	
	protected GeoStamp[] readTestCase(){
		int count = this.countLines();
		GeoStamp[] stamps = new GeoStamp[count];
		try{
			Scanner input = new Scanner(getResources().openRawResource(R.raw.test_case));
			
			int i = 0;
			while (input.hasNext()){
				double latitude = input.nextDouble();
				double longitude = input.nextDouble();
				int hour = input.nextInt();
				int minute = input.nextInt();
				int day = parseDayOfWeek(input.next());
				
				stamps[i] = new GeoStamp(latitude, longitude, hour, minute, day);
				i++;
			}
		}
		catch (Exception e){
			Log.v(TAG, "test_case: File Not Found");
			return null;
		}
		return stamps;
		
	}
	
	protected int parseDayOfWeek(String day){
		if (day.equalsIgnoreCase("Monday")){
			return 1;
		}
		else if (day.equalsIgnoreCase("Tuesday")){
			return 2;
		}
		else if (day.equalsIgnoreCase("Wednesday")){
			return 3;
		}
		else if (day.equalsIgnoreCase("Thursday")){
			return 4;
		}
		else if (day.equalsIgnoreCase("Friday")){
			return 5;
		}
		else if (day.equalsIgnoreCase("Saturday")){
			return 6;
		}
		else if (day.equalsIgnoreCase("Sunday")){
			return 7;
		}
		else 
			throw new InvalidParameterException();
	}

}


